<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>文件管理</title>
	<link href="/res/css/common/aztFile.css" rel="stylesheet">
	<link rel="stylesheet" href="/res/third/webupload/css/webuploader.css" type="text/css"/>
	<style type="text/css">
	.webuploader-pick{
		padding: 0px 5px;
	    position: relative;
	    top: -5px;
	}
	.webuploader-pick i{
		display: none;
	}
	.webuploader-pick a{
		color: white;
	    display: inline-block;
	    padding: 0;
	    width: 90px;
	    height: 35px;
	    line-height: 35px;
	    vertical-align: middle; 
	    font-size: 16px;
	}
	</style>
</head>
<body>
<div class="fileSysOuter">
	<div class="fileTop">
		<ul> 
			<li><a class="[#if initType?? && initType = 'image']fileTabPre[#else]titleNone[/#if]">图片管理</a></li>
			<li><a class="[#if initType?? && initType = 'file']fileTabPre[#else]titleNone[/#if]">文件管理</a></li> 
		</ul>
		<!--<img class="closeFsys" src="/res/images/file/fileClose_03.png"/> -->
	</div>
	<div class="fileNav">
		<p>
			<i class="myPic" style="height: 25px;vertical-align: middle;"></i>
			<dfn class="myPicInt">我的[#if initType?? && initType = 'image']图片[/#if][#if initType?? && initType = 'file']文件[/#if]</dfn>
			<span class="upPic  picker" style="border: none;float: right;padding-right: 0;"><i></i><a style="vertical-align: middle;">上传[#if initType?? && initType = 'image']图片[/#if][#if initType?? && initType = 'file']文件[/#if]</a></span>
			<!--<span class="upPic"><i style="background: url(/res/images/file/fileSum.png) -3px -50px no-repeat;margin-right: 10px;"></i><a style="vertical-align: middle;">新建文件夹</a></span>-->
			<!--<span class="upPic"><i style="background: url(/res/images/file/fileSum.png) -45px -130px no-repeat;"></i><a style="vertical-align: middle;">回收站</a></span>-->
			<!--<strong class="fileSearch">-->
				<!--<input type="text" placeholder="按文件名称搜索"/>-->
				<!--<i style="background: url(/res/images/file/fileSum.png) -82px -130px no-repeat;position: absolute;top: 8px;left:170px;cursor: pointer;"></i>-->
				<!--<a>高级搜索</a>-->
			<!--</strong>-->
		</p>
		<hr></hr>
		<div class="navTwo">
			 
				<!--<input style="vertical-align: middle;" type="checkbox"/><label style="vertical-align: middle;">全选</label>-->
				<!--<span class="upPic opFile"><i style="background: url(/res/images/file/fileSum.png) 0px -423px no-repeat;"></i><a style="vertical-align: middle;">替换</a></span>-->
				<!--<div class="navBar"></div>-->
				<!--<span class="upPic opFile"><i style="background: url(/res/images/file/fileSum.png) -190px -500px no-repeat;"></i><a style="vertical-align: middle;">移动</a></span>-->
				<!--<div class="navBar"></div>-->
				<!--<span class="upPic opFile"><i style="background: url(/res/images/file/fileSum.png) 0px -545px no-repeat;"></i><a style="vertical-align: middle;">重命名</a></span>-->
				<!--<div class="navBar"></div>-->
				<!--<span class="upPic opFile"><i style="background: url(/res/images/file/fileSum.png) -45px -425px no-repeat;"></i><a style="vertical-align: middle;">编辑</a></span>-->
				<!--<div class="navBar"></div>-->
				<!--<span class="upPic opFile"><i style="background: url(/res/images/file/fileSum.png) -120px -425px no-repeat;"></i><a style="vertical-align: middle;">适配手机</a></span>-->
				<!--<div class="navBar"></div>-->
				<span style="margin: 0 0 0 20px;"><input type="checkbox" style="margin-right: 5px;" onclick="choseAll(this)"/><span>全选</span><span style="margin: 0 15px;">|</span></span>
				<span class="upPic opFile delspan" style="padding: 0;"><img class="delItwo" src="/res/images/file/fileClose_07.png"/> <a style="vertical-align: middle;">删除</a></span>
				<!-- <div style="display: none" class="picker"></div> -->
			 
		</div>
		<hr></hr>
	</div>
	<div class="picShadow">
		<div class="fileSysContent">
			[#if pagination ?? && pagination.list??]
				[#list pagination.list as file]
					<div style="height: auto;" id="file_${file_index}" url="${file.url!}" fid="${file.id!}" fname = "${file.fileName!}" class="fileDiv [#if chioseId?? && file.id == chioseId]choised[/#if]">
						<p class="imgCont">
							<img alt="" src="[#if file.isFile]/res/images/common/fileImg.png[#else]${file.url!}[/#if]"/>
						</p>
						<b title="${file.fileName!}" class="picIntro">[@content_cut content=file.fileName! len=16 ending="..." /]</b>
					</div>
				[/#list]
			[/#if]
		</div>
	</div>
	<div class="fileSysFenYe">
		[#if pagination??]
			<ul>
				<li [#if pagination.pageNo != 1]onclick="fileFenYeGo(1);"[/#if]>首页</li>
				<li [#if pagination.pageNo != pagination.prePage]onclick="fileFenYeGo(${pagination.prePage!});"[/#if]>&lt;上一页</li>
				<li class="presentYe">${pagination.pageNo!}/${pagination.totalPage}</li>
				<li [#if pagination.pageNo != pagination.nextPage]onclick="fileFenYeGo(${pagination.nextPage!});"[/#if]>下一页&gt;</li>
				<li [#if pagination.pageNo != pagination.totalPage]onclick="fileFenYeGo(${pagination.totalPage!});"[/#if]>尾页</li>
			</ul>
		[/#if]
	</div>
	<div class="fileSysButt">
		<button type="button"  class="fileManagerSure">确认</button>
		<button type="button"  class="fileManagerCancel">取消</button>
	</div>
</div>
</body>

<script type="text/javascript" src="/res/third/webupload/js/webuploader.js"></script>
<script type="text/javascript">
	$(function(){ 
		$(".fileSysContent .fileDiv").click(function(){
			$(".fileSysContent").css({"border" : "none"});
			$(this).toggleClass("choised"); 
			var $this = $(this);
			[#if !multiple]
			$(".fileSysContent .fileDiv").each(function(){
				if($(this).attr("id") != $this.attr("id")){
					$(this).removeClass("choised"); 
				}
			});
			[/#if]
		});

		$(".fileManagerCancel").click(function(){
			fileOptions.cancel();
		});
		$(".fileManagerSure").click(function(){
			var choised = $(".fileSysContent .choised").length;
			if(choised == 0){
				$(".fileSysContent").css({"border" : "2px solid red"});
			}else{
				var files = [];
				var canSure = true;
				$(".fileSysContent .choised").each(function(){
					var file = {};
					file.url = $(this).attr("url");
					var name = $(this).attr("fname");
					if(fileOptions.choiseTypes != ""){
						if(fileOptions.choiseTypes.indexOf(name.substring(name.lastIndexOf(".") + 1 )) == -1){
							canSure = false;
							return false;
						}
					}
					file.name = name
					files.push(file);
				});
				if(!canSure){
					alert("只能选择"+fileOptions.choiseTypes+"类型的文件");
					return false;
				}
//                 layer.close(fileDialog);
				fileOptions.callback(files);
				fileOptions.close();
			}
		});

		$(".delspan").click(function(){
			var choised = $(".fileSysContent .choised").length;
			if(choised == 0){
				$(".fileSysContent").css({"border" : "2px solid red"});
			}else{
				var fids = [];
				$(".fileSysContent .choised").each(function(){
					if($(this).attr("fid") != ''){
						fids.push($(this).attr("fid"));
					}
				});
				if(fids.length > 0){
					layer.confirm("是否确认删除此文件？" , {icon : 3 , title : "提示"}  , function(index){
						$.ajax({
							url : '/user/delFile',
							type : 'post',
							data : {fids:fids.join(",")},
							success : function () {
								layer.close(index);
								fileOptions.loading();
							}
						});
					})
				}else{
					alert("临时文件，不能删除");
					return false;
				}

			}
		});



		var uploader = WebUploader.create({

			// swf文件路径
			swf: '/res/third/webupload/swf/Uploader.swf',

			// 文件接收服务端。
			server: '/res/third/ueditor/jsp/controller.jsp?action=uploadfile[#if userpath?? ]&userpath=${userpath!}[/#if]',

			// 选择文件的按钮。可选。
			// 内部根据当前运行是创建，可能是input元素，也可能是flash.
			pick: '.picker',

			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false ,

			fileSingleSizeLimit :fileOptions.fileSingleSizeLimit

			//auto : true,

//             [#if initType?? && initType == 'image']
//			  只允许选择图片文件。
//                accept: {
//                    title: 'Images',
//                    extensions: 'gif,jpg,jpeg,bmp,png',
//                    mimeTypes: 'image/*'
//                }
// 		    [/#if]




		});

		uploader.on( 'uploadSuccess', function( file , response) {
			if(response.state != "SUCCESS"){
				alert(response.state)
			}else{
				var file = {};
				file.fileName = response.originalName;
				file.url = response.url;
				file.suffix = response.type.substring(1);
				file.isImage = fileOptions.initType == 'image' ? 1 : 0;
				$.ajax({
					url : '/user/saveFile',
					type : 'post' ,
					data : file,
					success : function(fileId){
						fileOptions.loading(fileId);
					}
				});
			}
		});

		uploader.on( 'startUpload', function() {
			layer.load(2);
		});


		uploader.on( 'error', function(type) {
			if(type == "F_EXCEED_SIZE"){
				layer.msg("文件大小超过"+(fileOptions.fileSingleSizeLimit/1024/1024)+"M" , {time:1000});
			}
		});

		// 当有文件添加进来的时候
		uploader.on( 'fileQueued', function( file ) {
			var fileTypes = "doc,docx,xls,xlsx,ppt,pptx,zip,rar";
			var imageTypes = "gif,jpg,jpeg,bmp,png";
			var flag = false;
			var alertMsg = "不允许的文件类型！";

			if(fileOptions.suffixTypes != ""){
				if(fileOptions.suffixTypes.indexOf(file.ext.toLowerCase()) < 0){
					flag = true;
					alertMsg += "允许类型：("+fileOptions.suffixTypes+")";
				}
			}else{
				[#if initType?? && initType == 'image']
				if(imageTypes.indexOf(file.ext.toLowerCase()) < 0){
					flag = true;
					alertMsg += "允许类型：("+imageTypes+")";
				}
				[#else]
				if(fileTypes.indexOf(file.ext.toLowerCase()) < 0){
					flag = true;
					alertMsg += "允许类型：("+fileTypes+")";
				}
				[/#if]
			}

			if(flag){
				uploader.removeFile(file);
				alert(alertMsg);
				return false;
			}else{
				uploader.upload();
			}

		});

		$(".upPicBu").on('click' , function(){
			$(".picker label").trigger("click");
		}); 
		 
		/*图片悬浮**/
		$(".fileSysOuter").delegate(".picShadow .fileSysContent div", "mouseenter", function (event) { 
			var del='<img class="delFor" src="/res/images/file/delThre_03.png"/>';
			$(this).append(del);
			  
		}).delegate(".picShadow .fileSysContent div", "mouseleave", function (event) {  
			$(this).find(".delFor").remove();
		});  
		
		
		$(".fileSysOuter").delegate(".delFor","click",function(){
			var parentDiv = $(this).parents(".fileDiv");
			var fid = parentDiv.attr("fid");
			layer.confirm("是否确认删除此文件？" , {icon : 3 , title : "提示"}  , function(index){
				$.ajax({
					url : '/user/delFile',
					type : 'post',
					data : {fids:fid},
					success : function () {
						layer.close(index);
						parentDiv.remove();
					}
				});
			})
			return false;

			});
	});

	function changeTab(type){
		fileOptions.initType = type;
		fileOptions.loading();
		return false;
	}

	function fileFenYeGo(pageNo){
		fileOptions.pageNo = pageNo;
		fileOptions.loading();
		return false;
	}
	/*选择所有图片**/
	function choseAll(o){ 
		if ($(o).prop("checked")){
			$(".fileSysOuter .fileSysContent div").addClass("choised");
		}else{
			$(".fileSysOuter .fileSysContent div").removeClass("choised");
		}
	}

</script>
</html>
